<div id="tabs" class="flora">

	<ul>
		<li><a href="#fragment-1"><span>Notícias</span></a></li>
		<li><a href="#fragment-2"><span>Editor</span></a></li>
	</ul>

	<div id="fragment-1">

		<ul class="toolbar">
			<li><a class="toolbar-new" id="l1" href="#">Novo</a></li>
			<li><a class="toolbar-edit" id="l2" href="#">Editar</a></li>
			<li><a class="toolbar-delete" id="l3" href="#">Excluir</a></li>
		</ul>

		<div class="grid">
			<table id="formnews" class="scroll" cellpadding="0" cellspacing="0"></table>
			<div id="pagernews" class="scroll" style="text-align:center;"></div>
		</div>

	</div>

	<div id="fragment-2">

		<div id="pageEdit">
		</div>

	</div>
</div>

<div id="dialog" style="display:none;"></div>
<script>
$("#tabs > ul").tabs();

$("#l1").click( function(){
	$("#pageEdit").load('/news/formnews/new');
	$("#tabs > ul").tabs('select', 1);
});

$("#l2").click( function(){
    var id = jQuery("#formnews").getSelectedRow();
    if (id) {
        var ret = jQuery("#formnews").getRowData(id);
		$("#pageEdit").load('/news/formnews/edit/Id/'+ret.id);
		$("#tabs > ul").tabs('select', 1);
    } else { 
		alert("Selecione um registro!");
	}
});

$("#l3").click( function(){
    var id = jQuery("#formnews").getSelectedRow();
    if (id) {
		$('#dialog').dialog({
			title: 'Tem certeza em excluir este arquivo?',
			buttons: {
						'Yes': function() {
											$(this).parents('.ui-dialog:first').dialogClose();
											$('#alert').load('/news/formnews/delete/Id/'+id);
											$('#alert').fadeIn("slow");
											$("#list3").trigger("reloadGrid");
											//alert('You clicked \'Yes\'');
											//$('#dialog').dialogOpen();
										  },
						'No': function() { $(this).parents('.ui-dialog:first').dialogClose(); }
					 }
		});
	}
	else
	{
		alert("Selecione um registro!");
	}
});

$("#formnews").jqGrid({
    url:'/news/formnews/list',
    datatype: "json",
    colNames:['Código','Título'],
    colModel:[
		{name:'id',index:'id', width:70, sorttype:"int"},
		{name:'Title',index:'Title', width:200}
	],
	rowNum:10,
	rowList:[10,20,30],
	imgpath: '/default/scripts/jquery/jqGrid/images',
	pager: jQuery('#pagernews'),
	sortname: 'id',
	viewrecords: true,
	sortorder: "desc"
});

</script>
